#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<graphics.h>
#include<easyx.h>
#include "Graph.h"
#include "Menu.h"
#include "Mouse.h"
#include "Search.h"
using namespace std;
int main()
{
	Graph graph;
	Menu menu;
	graph.init();//Draw a 20*20 checkerboard
	menu.init();//Output menu keys at specified locations
	Mouse mouse;
	Search search; 
	int map_mode = 0;
	while (1)
	{
		if (mouse.action())//Determine whether the left mouse button is double-clicked
		{
			if (mouse.menujudge() > 100000) 
				cout << "here"<<mouse.menujudge() << endl; 
			else if (mouse.menujudge() == map_mode_low)//Randomly generate the coordinates of 100 obstacles and draw the obstacles
			{
				map_mode = map_mode_low;
				search.initblock(map_mode_low);
				graph.init_map(search);
				cout << "low" << endl;
			}
			else if (mouse.menujudge() == map_mode_high)//Randomly generate the coordinates of 150 obstacles and draw the obstacles
			{
				map_mode = map_mode_high; 
				search.initblock(map_mode_high);
				graph.init_map(search); 
				cout << "high" << endl;
			}
			else if (mouse.menujudge() == map_rebuild)//Regenerating the map
			{
				graph.erase_map();
				search.initblock(map_mode);
				graph.init_map(search);
				cout << "rebuild" << endl;
			}
			else if (mouse.menujudge() == map_erase)//Erase the map
			{
				graph.erase_map();
				cout << "erase" << endl;
			}
			else if (mouse.menujudge() == point_users)//The pattern that the starting and final points setted by yourself
			{
				while (!mouse.action())
				{
					int cnt = 0;
				}
				search.S=graph.init_points_to_solve(START, mouse); //Assign the algebraic value of the starting point to S
				while (!mouse.action())
				{
					int cnt = 0;
				}
				search.E=graph.init_points_to_solve(END, mouse);//Assign the algebraic value of the final point to S
				if(search.solve(point_users))//Use BFS algorithm  to find the shortest path and draw the shortest path
					graph.show_ans(search);
				else cout << "�޽�" << endl;
				cout << mouse.mapjudge() << endl;
				cout << "users" << endl;
			}
			else if (mouse.menujudge() == point_done)//The pattern that the starting and final points setted automatically
			{
				graph.init_points_to_solve(DONE, mouse);
				if(search.solve(point_done))//Use BFS algorithm  to find the shortest path and draw the shortest path
					graph.show_ans(search);
				else cout << "�޽�" << endl;
				cout << "done" << endl;
			}
			else if (mouse.menujudge() == replay)//Start all over again
			{
				graph.init();
				menu.init();
				cout << "replay" << endl;
			}
		}
	}
	_getchar_nolock();
	return 0;
}